﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;


namespace GameHungTrung.Entities
{
    class MySprite2D
    {
        #region MY CODE
        protected Texture2D _textureSprite;
        protected int _iLeft;
        protected int _iTop;
        protected int _iWidth;
        protected int _iHeight;

        ////protected MySprite2D(Texture2D texture, int left, int top, int width, int height)
        ////{
        ////    _textureSprite = texture;
        ////    _iLeft = left;
        ////    _iTop = top;
        ////    _iWidth = width;
        ////    _iHeight = height;

        ////}
        public bool isPointInSprite(MySprite2D sprite, int left, int top)
        {
            if ((sprite.LEFT <= left && sprite.LEFT + sprite.WIDTH >= left) &&
                       (sprite.TOP <= top && sprite.TOP + sprite.HEIGHT >= top))
                return true;
            return false;
        }
        public bool CheckCollisions(MySprite2D spriteB)
        {
            if (isPointInSprite(this, spriteB.LEFT, spriteB.TOP + spriteB.HEIGHT) ||
                    isPointInSprite(this, spriteB.LEFT + spriteB.WIDTH, spriteB.TOP + spriteB.HEIGHT) ||
                    isPointInSprite(this, spriteB.LEFT, spriteB.TOP) ||
                    isPointInSprite(this, spriteB.LEFT + spriteB.WIDTH, spriteB.TOP))
            {
                return true;
            }
            if (isPointInSprite(spriteB, this.LEFT, this.TOP + this.HEIGHT) ||
                    isPointInSprite(spriteB, this.LEFT + this.WIDTH, this.TOP + this.HEIGHT) ||
                    isPointInSprite(spriteB, this.LEFT, this.TOP) ||
                    isPointInSprite(spriteB, this.LEFT + this.WIDTH, this.TOP))
            {
                return true;
            }
            return false;
        }
        public virtual void Update()
        {
 
        }

        public void Draw(SpriteBatch g)
        {
            g.Draw(_textureSprite, new Rectangle(_iLeft, _iTop, _iWidth, _iHeight), Color.White);
        }

        public Texture2D TEXTURESPRITE
        {
            get { return _textureSprite; }
            set { _textureSprite = value; }
        }

        public int HEIGHT
        {
            get { return _iHeight; }
            set { _iHeight = value; }
        }

        public int WIDTH
        {
            get { return _iWidth; }
            set { _iWidth = value; }
        }

        public int TOP
        {
            get { return _iTop; }
            set { _iTop = value; }
        }

        public int LEFT
        {
            get { return _iLeft; }
            set { _iLeft = value; }
        }
        #endregion
    }
}
